/*   1:    */ package org.intellij.plugins.relaxNG.convert;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.ui.DocumentAdapter;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.nio.charset.Charset;
import java.util.*;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */ 
/*  41:    */ public class ConvertSchemaSettingsImpl
/*  42:    */   implements ConvertSchemaSettings
/*  43:    */ {
/*  44:    */   static final String OUTPUT_TYPE = "output-type";
/*  45:    */   static final String OUTPUT_PATH = "output-path";
/*  46:    */   private final PropertyChangeSupport a;
/*  47:    */   private final Project b;
/*  48:    */   private final SchemaType c;
/*  49:    */   private Map<String, ?> d;
/*  50:    */   private Map<String, ?> e;
/*  51:    */   private JPanel f;
/*  52:    */   private JRadioButton g;
/*  53:    */   private JRadioButton h;
/*  54:    */   private JRadioButton i;
/*  55:    */   private JRadioButton j;
/*  56:    */   private ComboBox k;
/*  57:    */   private JTextField l;
/*  58:    */   private JTextField m;
/*  59:    */   private TextFieldWithBrowseButton n;
/*  60:    */   
/*  61:    */   public ConvertSchemaSettingsImpl(Project paramProject, @NotNull SchemaType paramSchemaType, VirtualFile paramVirtualFile)
/*  62:    */   {
/*  63: 57 */     a();this.a = new PropertyChangeSupport(this);
/*  64:    */     
/*  65:    */ 
/*  66:    */ 
/*  67: 61 */     this.d = Collections.emptyMap();
/*  68: 62 */     this.e = Collections.emptyMap();
/*  69:    */     
/*  70:    */ 
/*  71:    */ 
/*  72:    */ 
/*  73:    */ 
/*  74:    */ 
/*  75:    */ 
/*  76:    */ 
/*  77:    */ 
/*  78:    */ 
/*  79:    */ 
/*  80:    */ 
/*  81:    */ 
/*  82:    */ 
/*  83:    */ 
/*  84:    */ 
/*  85: 79 */     this.b = paramProject;
/*  86: 80 */     this.c = paramSchemaType;
/*  87:    */     Object localObject1;
/*  88: 83 */     switch (3.$SwitchMap$org$intellij$plugins$relaxNG$convert$SchemaType[paramSchemaType.ordinal()])
/*  89:    */     {
/*  90:    */     case 1: 
/*  91: 85 */       this.g.setVisible(false);
/*  92: 86 */       this.i.setSelected(true);
/*  93: 87 */       localObject1 = StdFileTypes.XML;
/*  94: 88 */       break;
/*  95:    */     case 2: 
/*  96: 90 */       this.h.setVisible(false);
/*  97: 91 */       this.g.setSelected(true);
/*  98: 92 */       localObject1 = RncFileType.getInstance();
/*  99: 93 */       break;
/* 100:    */     case 3: 
/* 101: 95 */       this.i.setVisible(false);
/* 102: 96 */       this.g.setSelected(true);
/* 103: 97 */       localObject1 = StdFileTypes.XML;
/* 104: 98 */       break;
/* 105:    */     case 4: 
/* 106:100 */       this.j.setVisible(false);
/* 107:101 */       this.g.setSelected(true);
/* 108:102 */       localObject1 = StdFileTypes.DTD;
/* 109:103 */       break;
/* 110:    */     case 5: 
/* 111:105 */       this.g.setSelected(true);
/* 112:106 */       localObject1 = StdFileTypes.XML;
/* 113:107 */       break;
/* 114:    */     default: 
/* 115:109 */       if (!$assertionsDisabled) {
/* 116:109 */         throw new AssertionError();
/* 117:    */       }
/* 118:110 */       localObject1 = null;
/* 119:    */     }
/* 120:113 */     Charset[] arrayOfCharset = CharsetToolkit.getAvailableCharsets();
/* 121:114 */     ArrayList localArrayList = new ArrayList(arrayOfCharset.length);
/* 122:115 */     for (localSchemaType : arrayOfCharset) {
/* 123:116 */       if (localSchemaType.canEncode())
/* 124:    */       {
/* 125:117 */         localObject3 = localSchemaType.name();
/* 126:118 */         localArrayList.add(localObject3);
/* 127:    */       }
/* 128:    */     }
/* 129:122 */     this.k.setModel(new DefaultComboBoxModel(localArrayList.toArray()));
/* 130:123 */     ??? = EncodingManager.getInstance().getDefaultCharset();
/* 131:124 */     if (??? == null) {
/* 132:125 */       this.k.setSelectedItem(System.getProperty("file.encoding", "UTF-8"));
/* 133:    */     } else {
/* 134:127 */       this.k.setSelectedItem(((Charset)???).name());
/* 135:    */     }
/* 136:130 */     CodeStyleSettings localCodeStyleSettings = CodeStyleSettingsManager.getSettings(paramProject);
/* 137:131 */     ??? = localCodeStyleSettings.getIndentSize((FileType)localObject1);
/* 138:132 */     this.l.setText(String.valueOf(???));
/* 139:    */     
/* 140:134 */     this.m.setText(String.valueOf(localCodeStyleSettings.RIGHT_MARGIN));
/* 141:135 */     SchemaType localSchemaType = getOutputType();
/* 142:136 */     this.m.setEnabled((localSchemaType == SchemaType.DTD) || (localSchemaType == SchemaType.RNC));
/* 143:    */     
/* 144:138 */     Object localObject3 = FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor();
/* 145:139 */     Module localModule = ProjectRootManager.getInstance(paramProject).getFileIndex().getModuleForFile(paramVirtualFile);
/* 146:140 */     ((FileChooserDescriptor)localObject3).putUserData(LangDataKeys.MODULE_CONTEXT, localModule);
/* 147:    */     
/* 148:142 */     this.n.addBrowseFolderListener("Schema Conversion Destination", "Please select the destination the generated file(s) should be placed at", paramProject, (FileChooserDescriptor)localObject3);
/* 149:    */     
/* 150:    */ 
/* 151:145 */     JTextField localJTextField = this.n.getTextField();
/* 152:146 */     localJTextField.getDocument().addDocumentListener(new DocumentAdapter()
/* 153:    */     {
/* 154:    */       protected void textChanged(DocumentEvent paramAnonymousDocumentEvent)
/* 155:    */       {
/* 156:148 */         ConvertSchemaSettingsImpl.this.a.firePropertyChange("output-path", null, ConvertSchemaSettingsImpl.this.getOutputDestination());
/* 157:    */       }
/* 158:150 */     });
/* 159:151 */     localJTextField.setText(paramVirtualFile.getParent().getPath().replace('/', File.separatorChar));
/* 160:    */     
/* 161:153 */     ItemListener local2 = new ItemListener()
/* 162:    */     {
/* 163:    */       public void itemStateChanged(ItemEvent paramAnonymousItemEvent)
/* 164:    */       {
/* 165:155 */         if (paramAnonymousItemEvent.getStateChange() == 1)
/* 166:    */         {
/* 167:156 */           SchemaType localSchemaType = ConvertSchemaSettingsImpl.this.getOutputType();
/* 168:157 */           ConvertSchemaSettingsImpl.this.a.firePropertyChange("output-type", null, localSchemaType);
/* 169:158 */           ConvertSchemaSettingsImpl.this.m.setEnabled((localSchemaType == SchemaType.DTD) || (localSchemaType == SchemaType.RNC));
/* 170:    */         }
/* 171:    */       }
/* 172:161 */     };
/* 173:162 */     this.g.addItemListener(local2);
/* 174:163 */     this.h.addItemListener(local2);
/* 175:164 */     this.i.addItemListener(local2);
/* 176:165 */     this.j.addItemListener(local2);
/* 177:167 */     if (paramSchemaType == SchemaType.DTD) {
/* 178:168 */       this.d = AdvancedDtdOptions.prepareNamespaceMap(paramProject, paramVirtualFile);
/* 179:    */     }
/* 180:    */   }
/* 181:    */   
/* 182:    */   @NotNull
/* 183:    */   public SchemaType getOutputType()
/* 184:    */   {
/* 185:174 */     if (this.g.isSelected())
/* 186:    */     {
/* 187:175 */       SchemaType tmp13_10 = SchemaType.RNG;
/* 188:175 */       if (tmp13_10 == null) {
/* 189:175 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/convert/ConvertSchemaSettingsImpl", "getOutputType" }));
/* 190:    */       }
/* 191:175 */       return tmp13_10;
/* 192:    */     }
/* 193:176 */     if (this.h.isSelected())
/* 194:    */     {
/* 195:177 */       SchemaType tmp63_60 = SchemaType.RNC;
/* 196:177 */       if (tmp63_60 == null) {
/* 197:177 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/convert/ConvertSchemaSettingsImpl", "getOutputType" }));
/* 198:    */       }
/* 199:177 */       return tmp63_60;
/* 200:    */     }
/* 201:178 */     if (this.i.isSelected())
/* 202:    */     {
/* 203:179 */       SchemaType tmp113_110 = SchemaType.XSD;
/* 204:179 */       if (tmp113_110 == null) {
/* 205:179 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/convert/ConvertSchemaSettingsImpl", "getOutputType" }));
/* 206:    */       }
/* 207:179 */       return tmp113_110;
/* 208:    */     }
/* 209:181 */     assert (this.j.isSelected()); SchemaType 
/* 210:182 */       tmp177_174 = SchemaType.DTD;
/* 211:182 */     if (tmp177_174 == null) {
/* 212:182 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/convert/ConvertSchemaSettingsImpl", "getOutputType" }));
/* 213:    */     }
/* 214:182 */     return tmp177_174;
/* 215:    */   }
/* 216:    */   
/* 217:    */   public String getOutputEncoding()
/* 218:    */   {
/* 219:187 */     return (String)this.k.getSelectedItem();
/* 220:    */   }
/* 221:    */   
/* 222:    */   public int getIndent()
/* 223:    */   {
/* 224:191 */     return a(this.l.getText().trim());
/* 225:    */   }
/* 226:    */   
/* 227:    */   private static int a(String paramString)
/* 228:    */   {
/* 229:    */     try
/* 230:    */     {
/* 231:196 */       return paramString.length() > 0 ? Integer.parseInt(paramString) : -1;
/* 232:    */     }
/* 233:    */     catch (NumberFormatException localNumberFormatException) {}
/* 234:198 */     return -1;
/* 235:    */   }
/* 236:    */   
/* 237:    */   public int getLineLength()
/* 238:    */   {
/* 239:203 */     return a(this.m.getText());
/* 240:    */   }
/* 241:    */   
/* 242:    */   public String getOutputDestination()
/* 243:    */   {
/* 244:207 */     return this.n.getText();
/* 245:    */   }
/* 246:    */   
/* 247:    */   public void addAdvancedSettings(List<String> paramList1, List<String> paramList2)
/* 248:    */   {
/* 249:211 */     a(this.d, paramList1);
/* 250:213 */     if (getOutputType() == SchemaType.XSD) {
/* 251:214 */       a(this.e, paramList2);
/* 252:    */     }
/* 253:    */   }
/* 254:    */   
/* 255:    */   private static void a(Map<String, ?> paramMap, List<String> paramList)
/* 256:    */   {
/* 257:219 */     Set localSet = paramMap.keySet();
/* 258:220 */     for (String str : localSet)
/* 259:    */     {
/* 260:221 */       Object localObject = paramMap.get(str);
/* 261:222 */       if (localObject == Boolean.TRUE) {
/* 262:223 */         paramList.add(str);
/* 263:224 */       } else if (localObject == Boolean.FALSE) {
/* 264:225 */         paramList.add("no-" + str);
/* 265:226 */       } else if (localObject != null) {
/* 266:227 */         paramList.add(str + "=" + localObject);
/* 267:    */       }
/* 268:    */     }
/* 269:    */   }
/* 270:    */   
/* 271:    */   public JComponent getRoot()
/* 272:    */   {
/* 273:233 */     return this.f;
/* 274:    */   }
/* 275:    */   
/* 276:    */   public JComponent getPreferredFocusedComponent()
/* 277:    */   {
/* 278:237 */     return this.n;
/* 279:    */   }
/* 280:    */   
/* 281:    */   public void addPropertyChangeListener(String paramString, PropertyChangeListener paramPropertyChangeListener)
/* 282:    */   {
/* 283:241 */     this.a.addPropertyChangeListener(paramString, paramPropertyChangeListener);
/* 284:    */   }
/* 285:    */   
/* 286:    */   public void showAdvancedSettings()
/* 287:    */   {
/* 288:245 */     AdvancedOptionsDialog localAdvancedOptionsDialog = new AdvancedOptionsDialog(this.b, this.c, getOutputType());
/* 289:246 */     localAdvancedOptionsDialog.setOptions(this.d, this.e);
/* 290:    */     
/* 291:248 */     localAdvancedOptionsDialog.show();
/* 292:249 */     if (localAdvancedOptionsDialog.isOK())
/* 293:    */     {
/* 294:250 */       this.d = localAdvancedOptionsDialog.getInputOptions();
/* 295:251 */       this.e = localAdvancedOptionsDialog.getOutputOptions();
/* 296:    */     }
/* 297:    */   }
/* 298:    */   
/* 299:    */   public boolean hasAdvancedSettings()
/* 300:    */   {
/* 301:256 */     return (getOutputType() == SchemaType.XSD) || (this.c == SchemaType.DTD);
/* 302:    */   }
/* 303:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.convert.ConvertSchemaSettingsImpl

 * JD-Core Version:    0.7.0.1

 */